package com.nelson.musicplayer.base

import android.view.LayoutInflater
import android.view.ViewGroup
import com.alibaba.android.vlayout.DelegateAdapter
import com.alibaba.android.vlayout.LayoutHelper
import com.chad.library.adapter.base.BaseViewHolder
import com.nelson.musicplayer.R
import com.nelson.musicplayer.appContext

/**
 * @author nelson
 * @since 2020-07-29
 */
abstract class BaseDelegateAdapter(
    private var mLayoutId: Int,
    private var mViewTypeItem: Int
) : DelegateAdapter.Adapter<BaseViewHolder>() {


    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BaseViewHolder {
        if (viewType == mViewTypeItem) {
            return BaseViewHolder(LayoutInflater.from(appContext).inflate(mLayoutId, parent, false))
        } else {
            return BaseViewHolder(LayoutInflater.from(appContext).inflate(R.layout.default_item, parent, false))
        }
    }

    override fun getItemViewType(position: Int): Int {
        return mViewTypeItem
    }
}